package org.dromara.bzIns.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bzIns.domain.vo.InsCompanyVo;
import org.dromara.bzIns.domain.bo.InsCompanyBo;
import org.dromara.bzIns.service.IInsCompanyService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 保险公司信息
 *
 * @author bz_huaYal9146
 * @date 2025-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/bzIns/insCompany")
public class InsCompanyController extends BaseController {

    private final IInsCompanyService insCompanyService;

    /**
     * 查询保险公司信息列表
     */
    @SaCheckPermission("bzIns:insCompany:list")
    @GetMapping("/list")
    public TableDataInfo<InsCompanyVo> list(InsCompanyBo bo, PageQuery pageQuery) {
        return insCompanyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出保险公司信息列表
     */
    @SaCheckPermission("bzIns:insCompany:export")
    @Log(title = "保险公司信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InsCompanyBo bo, HttpServletResponse response) {
        List<InsCompanyVo> list = insCompanyService.queryList(bo);
        ExcelUtil.exportExcel(list, "保险公司信息", InsCompanyVo.class, response);
    }

    /**
     * 获取保险公司信息详细信息
     *
     * @param insCompanyId 主键
     */
    @SaCheckPermission("bzIns:insCompany:query")
    @GetMapping("/{insCompanyId}")
    public R<InsCompanyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long insCompanyId) {
        return R.ok(insCompanyService.queryById(insCompanyId));
    }

    /**
     * 新增保险公司信息
     */
    @SaCheckPermission("bzIns:insCompany:add")
    @Log(title = "保险公司信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody InsCompanyBo bo) {
        return toAjax(insCompanyService.insertByBo(bo));
    }

    /**
     * 修改保险公司信息
     */
    @SaCheckPermission("bzIns:insCompany:edit")
    @Log(title = "保险公司信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody InsCompanyBo bo) {
        return toAjax(insCompanyService.updateByBo(bo));
    }

    /**
     * 删除保险公司信息
     *
     * @param insCompanyIds 主键串
     */
    @SaCheckPermission("bzIns:insCompany:remove")
    @Log(title = "保险公司信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{insCompanyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] insCompanyIds) {
        return toAjax(insCompanyService.deleteWithValidByIds(List.of(insCompanyIds), true));
    }
}
